package com.cardlan.clsdk;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.ConnectivityManager;
import android.net.NetworkRequest;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.cardlan.twoshowinonescreen.ByteUtil;
import com.cardlan.twoshowinonescreen.CardLanStandardBus;
import com.cardlan.twoshowinonescreen.CardReadWriteUtil;
import com.cardlan.twoshowinonescreen.KeyErrorException;
import com.cardlan.twoshowinonescreen.Logs;
import com.cardlan.twoshowinonescreen.NetWorkListener;
import com.cardlan.twoshowinonescreen.ShellUtils;
import com.cardlan.twoshowinonescreen.TerminalConsumeDataForSystem;
import com.cardlan.twoshowinonescreen.thread.DefaultBaseNonUIThread;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import androidx.appcompat.app.AppCompatActivity;
import tp.xmaihh.serialport.SerialHelper;
import tp.xmaihh.serialport.bean.ComBean;

import static java.lang.String.format;

public class MainActivity extends AppCompatActivity {
    private static final int S_Reset_buffer_size = 32;
    private Button mBtn_initDev,resetCardBtn,readCardBtn,writeCardBtn,selectCpuBtn,redLedBtn;
    private Button greenLedBtn,buzzerBtn,relyBtn,pasmBtn,mediaBtn,nfcBtn,initPasmBtn;
    private Button netBtn,pasm1Btn,inputOptBtn;
    private TextView pasmIDTv;
    private TextView initPasmTv,mtv_content;
    EditText readSectorEt, readIndexEt,slotEt,baudRateEt;
    CardLanStandardBus mCardLanDevCtrl = new CardLanStandardBus();
    CardReadWriteUtil mReadWriteUtil = new CardReadWriteUtil();
    TerminalConsumeDataForSystem terminal;
    private String  mReadOrWriteKeyHexStr;
    private static final int GPIO_VALUE_HIGH = 1;
    private static final int GPIO_VALUE_LOW = 0;
    private static final int redGpio = 1255;
    private MediaPlayer mediaPlayer;
    private NetWorkListener networkCallback;
    private ConnectivityManager connectivityManager;
    private String netState = "NA";
    private StringBuffer sb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        terminal = new TerminalConsumeDataForSystem();
        mBtn_initDev = findViewById(R.id.mBtn_initDev);
        resetCardBtn = findViewById(R.id.mBtn_reset_card);
        readCardBtn = findViewById(R.id.mBtn_read_card);
        writeCardBtn = findViewById(R.id.mBtn_write_card);
        selectCpuBtn = findViewById(R.id.mBtn_select_cpu);
        redLedBtn = findViewById(R.id.mBtn_red_led);
        greenLedBtn = findViewById(R.id.mBtn_green_led);
        buzzerBtn = findViewById(R.id.mBtn_buzzer);
        relyBtn = findViewById(R.id.mBtn_relay_high);
        pasmBtn = findViewById(R.id.mBtn_pasm);
        pasmIDTv= findViewById(R.id.pasm_id);
        mediaBtn = findViewById(R.id.mBtn_media);
        nfcBtn = findViewById(R.id.mBtn_NFC);
        initPasmBtn = findViewById(R.id.mBtn_initPasm);
        slotEt = findViewById(R.id.mEt_slot);
        baudRateEt = findViewById(R.id.mEt_baudRate);
        initPasmTv = findViewById(R.id.mTxtView_pasm);
        netBtn = findViewById(R.id.mBtn_net);
        mtv_content = findViewById(R.id.mtv_content);
        pasm1Btn = findViewById(R.id.mBtn_initPasm1);
        inputOptBtn = findViewById(R.id.mBtn_getInputOpt);
        init();
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    private void init() {
        networkCallback = new NetWorkListener();
        networkCallback.setNetWorkCallBack(new NetWorkListener.NetCallBack() {
            @Override
            public void getNetState(boolean state) {
                Logs.d("state == " + state);
            }

            @Override
            public void setNetStateName(String netStateName) {
                Logs.d("netStateName == " + netStateName);
                netState = "Network state: " + netStateName;
            }
        });

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            NetworkRequest.Builder builder;
            builder = new NetworkRequest.Builder();
            NetworkRequest request = builder.build();
            connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            connectivityManager.registerNetworkCallback(request, networkCallback);
        }

        netBtn.setOnClickListener(v -> {
            mtv_content.setTextColor(getResources().getColor(R.color.line_success));
            mtv_content.setText(netState);
        });

        // init device
        mBtn_initDev.setOnClickListener(view -> new Thread(() -> {
            int initResult = mCardLanDevCtrl.callInitDev();
            if (0 == initResult || -2 == initResult|| -3 == initResult || -4 == initResult) {
                runOnUiThread(() -> {
                    mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                    mtv_content.setText(getResources().getString(R.string.init_dev) +" success!");
                });
            } else {
                runOnUiThread(() -> {
                    mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                    mtv_content.setText(getResources().getString(R.string.init_dev) +" failure!");
                });
            }
        }).start());

        //get the card sn
        resetCardBtn.setOnClickListener(v -> new Thread(() -> {
            byte[] resetBytes = mReadWriteUtil.getCardResetBytes();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (ByteUtil.notNull(resetBytes)) {
                        String mReadOrWriteKeyHexStr = ByteUtil.byteArrayToHexString(resetBytes);
                        mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                        mtv_content.setText(mReadOrWriteKeyHexStr);
                    } else {
                        mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                        mtv_content.setText("reset：failure! Please put the card on the card reader");
                    }
                }
            });

        }).start());

        //M1 card read
        readCardBtn.setOnClickListener(v -> {
//            char readSector = stringToChar(readSectorEt.getText().toString());
//            char readIndex = stringToChar(readIndexEt.getText().toString());
            byte[] resetByte = mReadWriteUtil.getCardResetBytes();
            if (!ByteUtil.notNull(resetByte)) {
                showToast(getResources().getString(R.string.not_find_card));
                mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                mtv_content.setText("read：failure! not find the card !");
                return;
            }
            Logs.e("SN == " + ByteUtil.byteArrayToHexString(resetByte));
            try {
                mReadOrWriteKeyHexStr = ByteUtil.byteArrayToHexString
                        (terminal.calculateNormalCardKey(resetByte));
            } catch (KeyErrorException e) {
                e.printStackTrace();
            }

            byte sector = 1;
            byte index = 0;
            byte[] readTemp = null;
            // the subsequent reads and writes need to be written using the computed read key
            long time = System.currentTimeMillis();
            readTemp = mReadWriteUtil.callReadJNI(ByteUtil.byteToHex(sector),
                    ByteUtil.byteToHex(index), mReadOrWriteKeyHexStr,null);
            time = System.currentTimeMillis() - time;
            if (ByteUtil.notNull(readTemp)) {
                mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                mtv_content.setText("The content of sector 0 block 0 is: "+ ByteUtil.byteArrayToHexString(readTemp) + "\n" + "time == " + time +"ms");
            }else{
                mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                mtv_content.setText("read：failure! Please put the card on the card reader");
            }
        });

        //M1 card write
        writeCardBtn.setOnClickListener(v -> {
            mReadOrWriteKeyHexStr = null;
            byte[] resetBytes = mReadWriteUtil.getCardResetBytes();
            if (!ByteUtil.notNull(resetBytes)) {
                showToast(getResources().getString(R.string.not_find_card));
                return;
            }
            try {
                mReadOrWriteKeyHexStr = ByteUtil.byteArrayToHexString
                        (terminal.calculateNormalCardKey(resetBytes));
            } catch (KeyErrorException e) {
                e.printStackTrace();
            }

            //int money= 100000;
            int writeResult =  mReadWriteUtil.callWriteJNI("4",
                    "1",
                    ByteUtil.byteArrayToHexString(new byte[4]),
                    mReadOrWriteKeyHexStr,null);
            if (writeResult == 5) {
                mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                mtv_content.setText("The content of sector 4 block 1 Writing successfully !");
            }
        });

        //cpu card
        selectCpuBtn.setOnClickListener(v -> {
            //File selection
            new DefaultBaseNonUIThread<byte[]>(){
                @Override
                public void doRun() {
                    mReadWriteUtil.initDev();
                    byte[] cardNumber = new byte[S_Reset_buffer_size];
                    int cardResult = mCardLanDevCtrl.callCardReset(cardNumber);
                    final byte[] initCpuConsumeBytes = terminal.selectCpuFile();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            if (!ByteUtil.notNull(initCpuConsumeBytes)) {
                                mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                                mtv_content.setText("read cpu card fail");
                            } else {
                                mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                                mtv_content.setText(getResources().getString(R.string.cpu_cmd)+ ByteUtil.byteArrayToHexString(initCpuConsumeBytes));
                            }
                        }
                    });
                }

                @Override
                public void doHandlerMsg(byte[] handlerEntity) {
                    Logs.e("Select File is failed!"+ByteUtil.byteArrayToHexString(handlerEntity));
                }

                @Override
                public void doHandlerMessage(Message handlerMessage) {

                }
            }.start();
        });

        redLedBtn.setOnClickListener(view -> toggleRedLed());

        greenLedBtn.setOnClickListener(view -> toggleGreenLed());

        buzzerBtn.setOnClickListener(view -> toggleBuzzer());

        relyBtn.setOnClickListener(view -> toggleRely());

        pasmBtn.setOnClickListener(view -> initPsam());

        mediaBtn.setOnClickListener(view -> {
            // 指定音频文件的路径。这里假设音频文件存放在res/raw目录下，文件名为hello
            int soundFileId = R.raw.hello; // 请确保在res/raw目录下有一个名为hello的音频文件

            // 创建MediaPlayer对象并设置音频文件
            mediaPlayer = MediaPlayer.create(this, soundFileId);

            // 开始播放音频
            playSound();
        });

        nfcBtn.setOnClickListener(view -> {
            byte[] resetByte = mReadWriteUtil.getCardResetBytes();
            if (!ByteUtil.notNull(resetByte)) {
                showToast(getResources().getString(R.string.not_find_card));
                mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                mtv_content.setText("Please put the card on the card reader");
                return;
            }
            Logs.e("SN == " + ByteUtil.byteArrayToHexString(resetByte));
            mtv_content.setTextColor(getResources().getColor(R.color.line_success));
            mtv_content.setText(format(getString(R.string.CardSN),ByteUtil.byteArrayToHexString(resetByte)));
        });

        initPasmBtn.setOnClickListener(v -> {
            sb = new StringBuffer();
            initPsam(115200);
            //next step Call callPsamSendCommand(int psamIndex, byte[] cmdArray, int cmdLen, byte[] receiveArray) Method
        });
        pasm1Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String slot = slotEt.getText().toString();
                String baudRate = baudRateEt.getText().toString();
                if(!TextUtils.isEmpty(slot)&&!TextUtils.isEmpty(baudRate)){
                    initPsam(Integer.parseInt(slot),Integer.parseInt(baudRate));
                }
            }
        });
        inputOptBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //0：两个无输入；
                //1；状态1有输入；
                //16：状态2有输入；
                //17：状态1和状态2有输入；
                int input = new CardLanStandardBus().getInputopt();
                mtv_content.setText("this input is " + input);
            }
        });
        //start QR
        startQRCode();
    }

    /**
     * scan code
     */
    public void startQRCode() {

        SerialHelper mSerialHelper = new SerialHelper("/dev/ttyHS1", 9600) {
            @Override
            protected void onDataReceived(ComBean comBean) {
                String qrcode = new String(comBean.bRec, StandardCharsets.UTF_8);
                Logs.e("scan string == " + qrcode);
                runOnUiThread(() -> {
                    mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                    mtv_content.setText(format(getString(R.string.scanContent),qrcode));
                });
            }
        };

        try {
            mSerialHelper.open();
            Logs.d("serial open== ");
        } catch (IOException e) {
            e.printStackTrace();
            Logs.d("serial == " + e.getMessage());
        }

    }

    Toast mToast;

    public void showToast(String msg) {
        if (mToast != null) {
            mToast.cancel();
            mToast = null;
        }
        mToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        mToast.show();
    }

    private char stringToChar(String string) {
        if (!ByteUtil.notNull(string)) {
            string = "0";
        }
        int iValue = Integer.parseInt(string);
        return (char) iValue;
    }

    //red led
    public void toggleRedLed() {
        String cmd="echo \"" + GPIO_VALUE_HIGH + "\">sys/class/gpio/gpio1253/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleRedLed: GPIO(%d) value=%d", redGpio, GPIO_VALUE_HIGH));
        mtv_content.setTextColor(getResources().getColor(R.color.line_success));
        mtv_content.setText("Check whether the LED light is red");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        cmd="echo \""+GPIO_VALUE_LOW + "\">/sys/class/gpio/gpio1253/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleRedLed: GPIO(%d) value=%d", redGpio, GPIO_VALUE_LOW));
    }

    //green led
    public void toggleGreenLed() {
        String cmd="echo \"" + GPIO_VALUE_HIGH + "\">sys/class/gpio/gpio1255/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleGreenLed: GPIO(%d) value=%d", redGpio, GPIO_VALUE_HIGH));
        mtv_content.setTextColor(getResources().getColor(R.color.line_success));
        mtv_content.setText("Check whether the LED light is greed");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        cmd="echo \""+GPIO_VALUE_LOW + "\">/sys/class/gpio/gpio1255/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleGreenLed: GPIO(%d) value=%d", redGpio, GPIO_VALUE_LOW));
    }

    //buzzer
    public static void toggleBuzzer() {
        String cmd="echo \"" + GPIO_VALUE_HIGH + "\">sys/class/gpio/gpio1239/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleBuzzer GPIO(%d) value=%d", redGpio, GPIO_VALUE_HIGH));
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        cmd="echo \""+GPIO_VALUE_LOW + "\">/sys/class/gpio/gpio1239/value";
        ShellUtils.execCommand(cmd,false);
        Logs.e(String.format(Locale.ENGLISH,"toggleBuzzer: GPIO(%d) value=%d", redGpio, GPIO_VALUE_LOW));
    }

    //Rely
    public void toggleRely() {

        new Thread(() -> {
            try {
                String relyState = "";
                int state = new CardLanStandardBus().relayOpt((char) 0,(char) 0);
                if(state <= 0){
                    relyState = "rely open one fail\n";
                    mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                }else{
                    relyState = "rely open one success\n";
                    mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                }
                String finalRelyState = relyState;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mtv_content.setText(finalRelyState);
                    }
                });

                Logs.d("relay one state == " + state);
                Thread.sleep(150);
                state = new CardLanStandardBus().relayOpt((char) 0,(char) 1);
                Logs.d("relay one state == " + state);
                Thread.sleep(150);
                state = new CardLanStandardBus().relayOpt((char) 1,(char) 0);
                if(state <= 0){
                    relyState = relyState + "rely open two fail";
                    mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                }else{
                    relyState = relyState + "rely open two success";
                    mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                }

                String finalRelyState1 = relyState;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mtv_content.setText(finalRelyState1);
                    }
                });
                Logs.d("relay two state == " + state);
                Thread.sleep(150);
                state = new CardLanStandardBus().relayOpt((char) 1,(char) 1);
                Logs.d("relay two state == " + state);
            } catch (InterruptedException e) {
                e.printStackTrace();
                mtv_content.setTextColor(getResources().getColor(R.color.line_fail));
                mtv_content.setText(e.getMessage());
            }

        }).start();
    }

    private static int count = 0;// 初始化失败后 重复初始化次数
    static byte[] psamNum = new byte[6];
    private static byte psamcard_keyindex = 0;
    private static int mPsamPort = 0;
    static byte[]  psamcard_psamnum = new byte[8];
    private static boolean isInitPsamOk = false;
    private void initPsam(){
        new Thread(() -> {
            if(!isInitPsamOk){
                if (count<=3){
                    byte[] psamKeyIndex = new byte[2];

                    Logs.d("Psam init ... ");
                    int result = new CardLanStandardBus().callInitTuPsam(psamNum,psamKeyIndex);
                    Logs.d("Psam result== " + result);
                    if(result > 0) {
                        psamcard_keyindex = psamKeyIndex[0];
                        mPsamPort = result -1;
                        Logs.d("psam卡号："+ ByteUtil.byteArrayToHexString(psamNum));
                        Logs.d("Psam init OK ... ");
                        Logs.d("psam keyIndex : " + ByteUtil.byteToHexString(psamcard_keyindex));
                        Logs.d("psam port : " + mPsamPort);
                        isInitPsamOk = true;
                        runOnUiThread(() -> pasmIDTv.setText(format(getResources().getString(R.string.pasmId),ByteUtil.byteArrayToHexString(psamNum))));
                    } else {
                        count++;
                        Logs.d("Psam init fail ... ");
                    }
                    Logs.d("--------------------------------------------------------------");
                }
            }else{
                Logs.d("Psam isInitPsamOk");
            }
        }).start();
    }

    private void initPsam(int baudRate){
        int initResult = mCardLanDevCtrl.callInitDev();
        ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(() -> {
            Logs.d("Psam init ... ");
            int result = new CardLanStandardBus().callInitPsam(0, baudRate);
            Logs.d("Psam result== " + result);
            if(result == 0) {
                Logs.d("Psam 0 init OK ... ");
                sb = sb.append("PSAM0测试").append(baudRate).append("成功").append(result).append("\n");
            } else {
                sb = sb.append("PSAM0测试").append(baudRate).append("失败").append(result).append("\n");
                Logs.d("Psam 0 init fail ... " + sb.toString());
            }
             });
        executor.submit(() -> {
            Logs.d("Psam init ... ");
            int result = new CardLanStandardBus().callInitPsam(1, baudRate);
            Logs.d("Psam result== " + result);
            if(result == 0) {
                Logs.d("Psam 1 init OK ... ");
                sb = sb.append("PSAM1测试").append(baudRate).append("成功").append(result).append("\n");
            } else {
                sb = sb.append("PSAM1测试").append(baudRate).append("失败").append(result).append("\n");
                Logs.d("Psam 1 init fail ... " + sb.toString());
            }
            }); // 任务2在任务1后执行
        executor.submit(() -> { /* 任务3 */
        Logs.d("Psam init ... ");
            int result = new CardLanStandardBus().callInitPsam(2, baudRate);
            Logs.d("Psam result== " + result);
            if(result == 0) {
                Logs.d("Psam 2 init OK ... ");
                sb = sb.append("PSAM2测试").append(baudRate).append("成功").append(result).append("\n");
            } else {
                sb = sb.append("PSAM2测试").append(baudRate).append("失败").append(result).append("\n");
                Logs.d("Psam 2 init fail ... " + sb.toString());
            }
            }); // 任务2在任务1后执行
        executor.submit(() -> { /* 任务3 */
            Logs.d("Psam init ... ");
            int result = new CardLanStandardBus().callInitPsam(3, baudRate);
            Logs.d("Psam result== " + result);
            if(result == 0) {
                Logs.d("Psam 3 init OK ... ");
                sb = sb.append("PSAM3测试" + baudRate + "成功" + result + "\n");
            } else {
                sb = sb.append("PSAM3测试").append(baudRate).append("失败").append(result).append("\n");
                Logs.d("Psam 3 init fail ... " + sb.toString());
            }
        }); // 任务2在任务1后执行
        executor.submit(() -> { /* 任务4 */
            Logs.d("Psam init ... ");
            int result = new CardLanStandardBus().callInitPsam(4, baudRate);
            Logs.d("Psam result== " + result);
            if(result == 0) {
                Logs.d("Psam 4 init OK ... ");
                sb = sb.append("PSAM4测试").append(baudRate).append("成功").append(result).append("\n");
            } else {
                sb = sb.append("PSAM4测试").append(baudRate).append("失败").append(result).append("\n");
                Logs.d("Psam 4 init fail ... " + sb.toString());

            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mtv_content.setText(sb.toString());
                }
            });
        });
    }

    private void initPsam(int psamIndex, int baudRate){
        count = 0;
        new Thread(() -> {

            if (count<=3){
                byte[] psamKeyIndex = new byte[2];

                Logs.d("Psam init ... ");
                int result = new CardLanStandardBus().callInitPsam(psamIndex, baudRate);
                Logs.d("Psam result== " + result);
                if(result == 0) {
                    psamcard_keyindex = psamKeyIndex[0];
                    mPsamPort = result -1;
                    Logs.d("Psam init OK ... ");
                } else {
                    count++;
                    Logs.d("Psam init fail ... ");
                }
                runOnUiThread(() -> initPasmTv.setText("init result "+ result));
                Logs.d("--------------------------------------------------------------");
            }

        }).start();
    }

    // 播放音频的方法
    private void playSound() {
        if (mediaPlayer != null) {
            mediaPlayer.start(); // 开始播放

            // 设置音频播放完毕后的监听器
            mediaPlayer.setOnCompletionListener(mp -> {
                releaseMediaPlayer(); // 播放完毕后释放资源
                mtv_content.setTextColor(getResources().getColor(R.color.line_success));
                mtv_content.setText("play sound success");
            });
        }
    }

    // 释放MediaPlayer资源的方法
    private void releaseMediaPlayer() {
        if (mediaPlayer != null) {
            mediaPlayer.stop(); // 停止播放
            mediaPlayer.release(); // 释放资源
            mediaPlayer = null; // 将对象置为null，以便垃圾回收
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        releaseMediaPlayer();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}